<?php
require_once 'empresa_business.php';
class segmentoBusiness 
{
	public static function getSegmentos() {
		$sql = "select * from segmento "; 
		$rs = dbManager::getArrayObj($sql);
		return $rs;
	}
	public static function getAllSegmentosByFilter($args){
		$sql = "SELECT * FROM `segmento` where nm_segmento like '%".$args['texto']."%' order by nm_segmento asc";
		$rs = dbManager::getArrayObj($sql);
		return $rs;
	
	}
	public static function persistSegmento($args){
		$id_segmento = $args['id_segmento'];
		if($args['id_segmento'] != ""){ 
			$segmento = dbManager::getEntityByFilter(new Segmento(), $id_segmento);
			
		}else{
			$segmento = new Segmento();
		}
		
		$segmento->nm_segmento = $args['nm_segmento']; 
		
		dbManager::persist($segmento);
		return $segmento;
	}
	
	 
	
	public static function excluirSegmento($args){
		$id_segmento = $args['id_segmento'];
		$rs = empresaBusiness::getAllEmpresasBySegmento($id_segmento);
		if($rs == false) {
				dbManager::deleteByFilter(new Segmento(), ' id_segmento =  '.$id_segmento);
				return true;
			}else{
				return false;
			}
			
		}
		
	
	}

?>